var FormUtils = {

	/**
	 * dialog中提交表单的通用方法
	 * @param {Vue} _that Vue实例 
	 * @param {String} formName form名
	 */
	submit: function(_that, formName, url, params, appendSuccessCallBack, successCallBack, errorCallBack) {
		_that.$refs[formName].validate(function(valid) {
			if(valid) {
				_that.loading = true;
				$.ajax({
					type: "post",
					"url": url,
					data: params,
					cache: false,
					success: function(data) {
						_that.loading = false;
						if(typeof successCallBack === 'function') {
							successCallBack(data);
						} else {
							if(data.status == 0) {
								parent._vue.$message({
									message: "操作成功",
									type: 'success'
								});
								//关闭弹出框
								_that.closeDlalog();
								//刷新表格
								parent.queryList();
								if(typeof appendSuccessCallBack === 'function') {
									appendSuccessCallBack(data);
								}
							} else {
								_that.$message({
									message: data.msg,
									type: 'error'
								});
							}
						}
					},
					error: function(xhr, msg, e) {
						if(typeof errorCallBack === 'function') {
							errorCallBack(xhr, msg, e);
						} else {
							_that.$message({
								message: "操作失败",
								type: 'error'
							});
						}
					},
					complete: function() {
						_that.loading = false;
					}
				});
			} else {
				return false;
			}
		});
	}

};

//通用的vue方法
var commonMethods = {
	handlePageSizeChange: function(val) {
		this.pagination.pageSize = val;
		if(this.pagination.currentPage == 1) {
			queryList();
		} else {
			this.pagination.currentPage = 1;
		}
	},
	handlePageCurrentChange: function(val) {
		queryList();
	},
	onOpen: function(iframeName, url) {
		this[iframeName].url = url;
	},
	onClose: function(iframeName) {
		this[iframeName].url = "";
	}
};

function successHandle(data, success, error) {
	if(data.status == 0) {
		if(typeof success === 'function') {
			success(data);
		}
	} else {
		if(typeof error === 'function') {
			error(data);
		}
	}
}